<?php

	// +----------------------------------------------------------------------
	// | 分类控制器
	// +----------------------------------------------------------------------
	// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
	// +----------------------------------------------------------------------
	// | Author: 微尘 <yicmf@qq.com>
	// +----------------------------------------------------------------------

	namespace app\controller\app\admin;

	use yicmf\builder\Edit;
	use yicmf\builder\Table;
	use think\facade\Url;
	use app\controller\admin\Common;
    use app\model\ucenter\MemberInfo as MemberInfoModel;


	class MemberInfo extends Common
	{
		protected function initialize()
		{
			parent::initialize();
		}

		public function _filter()
		{
		}

		public function index()
		{
			//读取规则列表
			$map = $this->_search($this->dbname);
            $map[] = ['id','<',4];
			//            //显示页面
			$builder = new Table();
			$builder ->model(MemberInfoModel::class)
                ->where($map)
                ->order('id DESC')
                ->setSearchPostUrl('', '')
//				->searchText('title', '搜索标题：', '标题')
//				->buttonUpdate('update', '新增动态')
				->keyId()
                ->keyText('type', '等级',false,50)
                ->keyText('condition', '升级条件')
                ->keyText('upgrade', '预存款提示')
                ->keyText('gradeIncome','等级收益')
				->actionUpdate();
			return $builder->fetch();
		}

		/**
		 * 编辑分类
		 * @access protected
		 * @author 微尘 <yicmf@qq.com>
		 */
		public function update()
		{
			if ($this->request->isPost()) { //提交表单
				 if ($this->request->param('id'))
                 {
                     $data = MemberInfoModel::where('id',$this->request->param('id'))->find();
                     $info = $this->request->only(['condition','upgrade','gradeIncome']);
                     $data->save($info);
                     $this->_returnSuccess( '更新成功');
                 }
			} else {
				/* 获取分类信息 */
				$id = $this->request->get('id');
				$isEdit = $id ? true : false;
				if ($isEdit) {
					$data = MemberInfoModel::where('id',$id)->find();
					if (!$data) {
						$this->_returnError( '操作错误');
					}
				} else {
                    $this->_returnError( '操作错误');
				}


			        $builder = new Edit();
				$builder->title('等级介绍')

                    ->keyEditor('condition', '升级条件');

                if ($data['id'] == 2)
                {
                    $builder->keyEditor('upgrade', '预存款提示');
                }

                $builder->keyEditor('gradeIncome','等级收益')
					->data($data)
					->buttonSubmit('', '保存');
				//                    ->buttonClose();
				return $builder->fetch();
			}
		}
	}